package autoorder.zsxmlv.action;

import autoorder.zsxmlv.po.Goods;
import autoorder.zsxmlv.po.Order;
import autoorder.zsxmlv.service.AccountService;
import autoorder.zsxmlv.service.GoodsService;
import autoorder.zsxmlv.service.OrderService;
import common.zsxmlv.vo.Result;
import common.zsxmlv.vo.Table;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: ZSXM
 * @Description:
 * @Company: DingZheng
 * @Date: Create by 2018/6/10 15:53
 * @Version: 1.0
 * @Modify by:
 */
@Controller
@RequestMapping("/admin/auto_order/order")
public class OrderAction {


    @Resource
    private OrderService orderService;
    @Resource
    private GoodsService goodsService;
    @Resource
    private AccountService accountService;


    @RequestMapping("/pay")
    public String pay(Integer orderId, HttpServletRequest request) {
        Order order = orderService.getOrderById(orderId);
        Goods goods = goodsService.getGoodsById(order.getGoodsId());
        Result result = accountService.getAccountById(order.getUserId());
        System.out.println(order.toString());
        request.setAttribute("goods", goods);
        request.setAttribute("order", order);
        request.setAttribute("account", result.getData());
        return "/admin2/pay";
    }

    @ResponseBody
    @RequestMapping("/selectByPage")
    public Table selectByPage(Integer page, Integer limit,String keyword, Integer status) {
        return orderService.selectByPage(page, limit, keyword, status);
    }

    @ResponseBody
    @RequestMapping("/sureOrderStatus")
    public Result sureOrderStatus(String orderNum) {
        return orderService.updateOrderStatusByOrderNum(orderNum);
    }


}
